package com.yellow.jobs;

import com.yellow.constant.RedisConstant;
import com.yellow.utils.AliyunOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

//定时清理图片
public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;

    public void clearImg() {
        //获取redis中存储的不同的数据
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        for (String fileName : sdiff) {
            //删除图片服务器的垃圾图片
            AliyunOSSUtils.deleteAiyunOOS(fileName);
            //删除redis集合中的数据
            jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES, fileName);
        }

    }

}
